package num50;

import java.util.ArrayList;

/**
 * @author : DuJiabao
 * @Date : 2021/2/6 19:43
 * @Project : sword-finger-offer
 * @File : null.java
 * @Desc : 分治思想。
 */
public class Solution {
    public double myPow(double x, int n) {
        return recursion(x, (long) n);
    }

    public double recursion(double x, long n) {
        if (n == 0) return 1;
        if (n == 1) return x;
        if (n < 0) return 1 / recursion(x, -n);
        if (n % 2 == 0)
            return recursion(x * x, n / 2);
        else
            return x * recursion(x * x, (n - 1) / 2);
    }
}
